package com.example.kotlin01

//为String类添加扩展函数lastChar
//get为String的自带方法，legth为自带属性
fun String.lastChar(): Char = get(length - 1)

//为Int 添加doubleValue扩展函数，this为自身
fun Int.doubleValue(): Int = this * 2

fun test2() {
    var name = "weishixiong"
    println(name.lastChar())
    var value = 10
    println(value.doubleValue())

}

fun String.firstChar():Char = get(0)


var String.doubleLength: Int
    get() = length * 2
    set(value) {
    }


//为MyExtent添加静态的扩展函数  getValue
fun MyExtent.Companion.getValue():Int = value



//为MyExtent添加静态的扩展函数  getDouvleValue
fun MyExtent.Companion.getDouvleValue(): Int {
    return value * 2
}

open class MyExtent {
    companion object {
        //静态成员
        val value = 10
        open fun myTest(){}
    }
}


fun main() {
   var view: MyView = MyButton()
    view.click()
    view.longClick()
}

open class MyView{
    open fun click(){
        println("MyView....")
    }
}
 class MyButton:MyView(){
     override fun click(){
        println("MyButton....")
    }
}
fun MyView.longClick() =  println("MyView....")

fun MyButton.longClick() = println("MyButton....")











